angular.module('inspinia').controller('shareDeductionSetCtrl',function($scope,$http,$state,$stateParams,SweetAlert,$compile,$uibModal,i18nService){
    i18nService.setCurrentLang('zh-cn');  //设置语言为中文
    
    $scope.info = {rate:90,effectiveDate:"",disabled:true,modifyRate:90};
    
    $scope.updateSet = function(){
    	$scope.info.disabled = false;
    }
    
    $http.post("shareDeductionSet/home",
    		{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
    		.success(function (result) {
    			if(result.status){
    				var data = result.data;
    				$scope.info.rate = + data.rate;
    				$scope.info.modifyRate = data.modifyRate;
    				$scope.info.effectiveDate = data.effectiveDate;
    				
    			}else {
    				$scope.notice(result.msg);
    			}
		        
    })
    
    $scope.noNumbers=function(e,len){
    	var val = e.target.value;
    	if(!val){
    	return;
    	}
    	var b = parseFloat(val);
    	e.target.value = Number(b).toFixed(len);
    	$scope.info.rate = + Number(b).toFixed(len);
    };
    $scope.toLimit = function(item,newValue,oldValue){
    	console.info(item);
    	console.info(newValue);
    	console.info(oldValue);
    if(!newValue){
    	return ;
    }
	　　if(/^\d*(\.\d{0,2})?$/.test(newValue)==false){
	　　　　item.rate=+oldValue;
	　　}
	};

    $scope.saveSet = function () {
        SweetAlert.swal({
                title: "确认修改？",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "提交",
                cancelButtonText: "取消",
                closeOnConfirm: true,
                closeOnCancel: true
            },
            function (isConfirm) {
                if (isConfirm) {
                	if (!$scope.info.rate) {
                		$scope.notice("比例在90%~100%之间");
                		return;
                	}
                    $http.post("shareDeductionSet/save","rate="+$scope.info.rate,{headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).success(function (result) {
                        if(result.status){
                        	$scope.notice(result.msg);
                        	location.reload();
                        }
                    })
                }
            });
    }
})
